//
// Created by 11401 on 25-7-9.
//

#include "tim_s.h"
#include "tim.h"

Screws_t  Screws;
void Screws_init(void)
{
        HAL_TIM_Base_Start_IT(&htim8);
        HAL_TIM_PWM_Start(&htim8,TIM_CHANNEL_2);
        __HAL_TIM_SET_COMPARE(&htim8,TIM_CHANNEL_2,0);
}

void Screws_up(uint16_t num)
{
        Screws.Number_targets=num;
        HAL_GPIO_WritePin(GPIOC,GPIO_PIN_6,1);
        __HAL_TIM_SET_COMPARE(&htim8,TIM_CHANNEL_2,300);
}

void Screws_down(uint16_t num)
{
        Screws.Number_targets=num;
        HAL_GPIO_WritePin(GPIOC,GPIO_PIN_6,0);
        __HAL_TIM_SET_COMPARE(&htim8,TIM_CHANNEL_2,500);
}

void Screws_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
        if (htim->Instance==TIM8)
        {
                Screws.Number_Actuals++;
                if ( Screws.Number_Actuals==Screws.Number_targets)
                {
                        __HAL_TIM_SET_COMPARE(&htim8,TIM_CHANNEL_2,0);
                }
        }


}